package com.itheima.controller.systemInfo;

import com.itheima.domin.pojo.Emp;
import com.itheima.domin.query.EmpQuery;
import com.itheima.domin.vo.Result;
import com.itheima.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 员工控制
 * @Author:上官徵羽
 * @Date: 2025/07/11 15:15
 * @Description TODO 今日内容:
 */
@RestController
@RequestMapping(value = "/emps")
@Slf4j
public class EmpController {
    @Autowired
    private EmpService empService;

    /**
     * 查询全部员工
     * @return
     */
    @GetMapping(value = "/list")
    public Result select1(){
        return Result.success(empService.select());
    }

    /**
     * 查询员工列表
     * @param empQuery
     * @return
     */

    @GetMapping
    public Result select(EmpQuery empQuery) {
        log.info("empQuery:{}", empQuery);

        return Result.success(empService.pageQuery(empQuery));
    }

    /**
     * 新增员工及工作经验
     * @param emp 员工实现类
     * @return
     */
    @PostMapping
    public Result addEmpAndExp(@RequestBody Emp emp){
        empService.addEmpAndExp(emp);
        return Result.success();
    }

    /**
     * 批量删除员工
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result deleteEmp(@RequestParam("ids") List<Integer> ids){
        log.info("EmpController deleteEmp:{}", ids);
        try {
            empService.deleteEmp(ids);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.success();
    }

    /**
     * 员工数据回显
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result selectIdEmp(@PathVariable Integer id){
        return Result.success(empService.selectIdEmp(id));
    }

    /**
     * 修改员工信息
     * @return
     */
    @PutMapping
    public Result updateId(@RequestBody Emp emp){
        empService.updateId(emp);
        return Result.success();
    }
}
